package com.zhkj.shixi.tvplayer.PicturePlayer;

import android.app.Activity;
import android.graphics.BitmapFactory;

import com.zhkj.shixi.tvplayer.Interface.PictureInfo;

import java.io.File;
import java.text.SimpleDateFormat;

/**
 * Created by suqiuyu on 19-8-9.
 */

public class PicInfo implements PictureInfo {
    private Activity mActivity;

    public PicInfo(Activity activity) {
        mActivity = activity;
    }

    @Override
    public String getPicDate() {
        File file = ((PicPlayActivity) mActivity).getFile();
        Long fileTime = file.lastModified();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy.MM.dd");
        String dateTime=formatter.format(fileTime);
        return dateTime;
    }

    @Override
    public String getPicName() {
        File file = ((PicPlayActivity) mActivity).getFile();
        String name = file.getName();
        return name;
    }

    @Override
    public String getPicSize() {
        File file = ((PicPlayActivity) mActivity).getFile();
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeFile(file.getPath(), options);
        int height = options.outHeight;
        int width = options.outWidth;
        String size = "" + width + "x" + height + "像素";
        return size;
    }

    @Override
    public String getPicType() {
        File file = ((PicPlayActivity) mActivity).getFile();
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeFile(file.getPath(), options);
        String type = options.outMimeType;
        if (type == null) {
            type = "unknown";
        } else {
            type = type.substring(6, type.length());
        }
        return type;
    }
}
